/**
 * 主页js
 */
if (location.href == "http://gdj.jl.gov.cn/" || location.href == "http://gdj.jl.gov.cn/index.html") {
	//=================================================	国务院iframe 开始=================================================	

	//将iframe所包含的a链接数 第一个a元素 最后一个a元素赋值给第一个参数的js对象
	_EsdDynamicTransformationScript.getIframeInfos = function(jsObj,iframeObj){
		if(iframeObj != undefined){
			jsObj.aLink_num = iframeObj.contentWindow.document.getElementsByTagName("a").length;
			jsObj.first_aLink = iframeObj.contentWindow.document.getElementsByTagName("a")[0];
			jsObj.last_aLink = iframeObj.contentWindow.document.getElementsByTagName("a")[jsObj.aLink_num-1];
			jsObj.self = iframeObj;
		}
	};

	//声明iframe操作对象
	_EsdDynamicTransformationScript.iframe1 = {};
	_EsdDynamicTransformationScript.iframe2 = {};

	_EsdDynamicTransformationScript.iframeElement1 = document.getElementsByTagName("iframe")[0];   // 需要修改 这里的iframe获取
	_EsdDynamicTransformationScript.iframeElement2 = document.getElementsByTagName("iframe")[1];   // 需要修改 这里的iframe获取

	//选项卡标签 jquery对象
	_EsdDynamicTransformationScript.iframeTab1 = $("#bywdt1 a");  // 需要修改 这里的tab获取
	_EsdDynamicTransformationScript.iframeTab2 = $("#bywdt2 a");  // 需要修改 这里的tab获取

	// 判断iframe是否有效
	if((_EsdDynamicTransformationScript.iframeElement1!=undefined) && (_EsdDynamicTransformationScript.iframeElement2!=undefined)){

		// 当iframe都加载完毕后执行代码 使用setInterval
		_EsdDynamicTransformationScript.iframeInterval = setInterval(function(){
			
			if((_EsdDynamicTransformationScript.iframeElement1.contentWindow.document.getElementsByTagName("a")[0]!=undefined) 
				&&_EsdDynamicTransformationScript.iframeElement2.contentWindow.document.getElementsByTagName("a")[0]!=undefined ){
				clearInterval(_EsdDynamicTransformationScript.iframeInterval);
				
				//通过方法赋值   
				_EsdDynamicTransformationScript.getIframeInfos(_EsdDynamicTransformationScript.iframe1,_EsdDynamicTransformationScript.iframeElement1);  
				_EsdDynamicTransformationScript.getIframeInfos(_EsdDynamicTransformationScript.iframe2,_EsdDynamicTransformationScript.iframeElement2); 

					//第一个标签 切换
				_EsdDynamicTransformationScript.iframeTab1.focus(function (e) {
					console.log("tab1获取到焦点");
					try{
						e = $(this).mousemove();
					}catch(e){
						console.log("报错了...");
					}
					$(document).bind("keydown.iframeKeydown_1", function (e) {
						if (e.shiftKey && e.keyCode == 9) {
							console.log("tab1向回切换");
							_EsdDynamicTransformationScript.iframeTab1.trigger("blur");
						} else if (e.keyCode == 9) {
							console.log("tab1继续切换到iframe上");
							_EsdDynamicTransformationScript.iframeTab1.trigger("blur");
							$(_EsdDynamicTransformationScript.iframe1.self).focus();
							$(_EsdDynamicTransformationScript.iframe1.first_aLink).focus();
							console.log(document.activeElement);
							return false;
						}
					});
				});
				_EsdDynamicTransformationScript.iframeTab1.blur(function () {
					$(document).unbind("keydown.iframeKeydown_1");
				});

				// 第一个标签的第一个链接
				$(_EsdDynamicTransformationScript.iframe1.first_aLink).focus(function () {
					console.log("第一个iframe的第一条获得焦点");
					$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).bind("keydown.iframeKeydown_first1", function (e) {
						if (e.shiftKey && e.keyCode == 9) {
							console.log("第一个iframe的第一条向上切换");
							$(document).trigger("blur");
							_EsdDynamicTransformationScript.iframeTab1.focus();
							return false;
						} else if (e.keyCode == 9) {
							console.log("第一个iframe的第一条继续切换");
						}
					});
				});
				$(_EsdDynamicTransformationScript.iframe1.first_aLink).blur(function () {
					$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).unbind("keydown.iframeKeydown_first1");
				});

				// 第一个标签的最后一个链接
				$(_EsdDynamicTransformationScript.iframe1.last_aLink).focus(function () {
					console.log("第一个iframe的最后一条获得焦点");
					$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).bind("keydown.iframeKeydown_first1", function (e) {
						if (e.shiftKey && e.keyCode == 9) {
							console.log("第一个iframe的最后一条向上切换");
						} else if (e.keyCode == 9) {
							console.log("第一个iframe的最后一条继续切换 到下一个标签");
							$(document).trigger("blur");
							$(_EsdDynamicTransformationScript.iframe1.self).trigger("blur");
							//_EsdDynamicTransformationScript.iframeTab2.focus();
							$(".ywdt_new li:eq(1) a").focus();
							return false;
						}
					});
				});
				$(_EsdDynamicTransformationScript.iframe1.last_aLink).blur(function () {
					$(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).unbind("keydown.iframeKeydown_first1");
				});

			


				$(".ywdt_new li:eq(1) a").focus(function (e) {
					$(document).bind("keydown.iframeKeydown_3", function (e) {
						if (e.shiftKey && e.keyCode == 9) {
							_EsdDynamicTransformationScript.iframeTab2.trigger("blur");
							try{
								_EsdDynamicTransformationScript.iframeTab1.mousemove();
							}catch(e){
								console.log("报错了...");
							}
							$(_EsdDynamicTransformationScript.iframe1.last_aLink).focus();
							return false;
						} else if (e.keyCode == 9) {
							
						}
					});
			
				});
				$(".ywdt_new li:eq(1) a").blur(function () {
					$(document).unbind("keydown.iframeKeydown_3");
				});
			
				//第二个标签切换
				_EsdDynamicTransformationScript.iframeTab2.focus(function (e) {
					console.log("tab2获取到焦点");
					try{
						e = $(this).mousemove();
					}catch(e){
						console.log("报错了...");
					}
					$(document).bind("keydown.iframeKeydown_2", function (e) {
						if (e.shiftKey && e.keyCode == 9) {
							console.log("第二个标签向回切换 到第一个标签的最后一条");
							_EsdDynamicTransformationScript.iframeTab2.trigger("blur");
							//_EsdDynamicTransformationScript.iframeTab1.mousemove();
							//$(_EsdDynamicTransformationScript.iframe1.last_aLink).focus();
							$(".ywdt_new li:eq(1) a").focus();
							return false;
						} else if (e.keyCode == 9) {
							_EsdDynamicTransformationScript.iframeTab2.trigger("blur");
							$(_EsdDynamicTransformationScript.iframe2.self).focus();
							console.log(document.activeElement);
							return false;
						}
					});

				});
				_EsdDynamicTransformationScript.iframeTab2.blur(function () {
					$(document).unbind("keydown.iframeKeydown_2");
				});

			}
			
		}, 500);

	}

	//=================================================	国务院iframe 结束=================================================	
	
	$("form[name='login'] input:first").attr({placeholder:"用户名",title:"用户名"});
	$("form[name='login'] input:last").attr({placeholder:"密码",title:"密码"});
	
}